package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyTchycz;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyTchyczMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyTchyczParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyTchyczResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyTchyczService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 天财会员充值 服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-06-03
 */
@Service
public class BtyTchyczServiceImpl extends ServiceImpl<BtyTchyczMapper, BtyTchycz> implements BtyTchyczService {

    @Override
    public void add(BtyTchyczParam param){
        BtyTchycz entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyTchyczParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyTchyczParam param){
        BtyTchycz oldEntity = getOldEntity(param);
        BtyTchycz newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyTchyczResult findBySpec(BtyTchyczParam param){
        return null;
    }

    @Override
    public List<BtyTchyczResult> findListBySpec(BtyTchyczParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyTchyczParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public boolean insertTchycz(List<BtyTchycz> list) {
        return baseMapper.insertTchycz(list);
    }

    private Serializable getKey(BtyTchyczParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyTchycz getOldEntity(BtyTchyczParam param) {
        return this.getById(getKey(param));
    }

    private BtyTchycz getEntity(BtyTchyczParam param) {
        BtyTchycz entity = new BtyTchycz();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
